using System;
using System.Collections.Generic;
using ProjectBase.Utils;
using System.ComponentModel;
using Iesi.Collections.Generic;

namespace Clanta.Core.Domain
{
    [Serializable]
    public class Customer : VersionDomainObject<long, long>
    {
        #region Constructors

        protected Customer()
        {
        }

        public Customer(string name)
        {
            Name = name;
        }

        #endregion

        #region Properties

        [DataObjectField(false)]
        public virtual string Name
        {
            get { return name; }
            set
            {
                Check.Require(!string.IsNullOrEmpty(value), "The customer name must be provided");
                name = value;
            }
        }

        public virtual IList<Conference> Conferences
        {
            get { return conferences; }
            protected set { conferences = value; }
        }

        public virtual ISet<User> Users
        {
            get { return users; }
            protected set { users = value; }
        }

        #endregion

        #region Methods

        public override bool Equals(object obj)
        {
            if (obj == null || !GetType().Equals(obj.GetType()))
            {
                return false;
            }
            Customer compareTo = (Customer)obj;

            if (!IsTransient() && !compareTo.IsTransient())
            {
                return Id == compareTo.Id && Version == compareTo.Version;
            }

            return object.Equals(Name, compareTo.Name);
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("Id={0}, Version={1}, Name={2}", Id, Version, Name);
        }

        #endregion

        #region Fields

        private string name;

        private IList<Conference> conferences = new List<Conference>();

        private ISet<User> users = new HashedSet<User>();

        #endregion
    }
}
